<template>
  <!--盘点列表  唐美莉 -->
  <section>
    <table
      border="0"
      width="100%"
      style="border-spacing: 0;border-collapse: collapse;"
    >
      <tr>
        <td>
          <el-form :inline="true">
            <el-form-item>
              <el-button
                type="primary"
                :disabled="!qxBtns.add"
                plain
                @click="addDurg(null, 1)"
                >+添加盘点</el-button
              >
            </el-form-item>
            <!-- <el-form-item>
              <el-button
                type="primary"
                :disabled="!qxBtns.add"
                plain
                @click="addDurg(null, 2)"
                >+添加月度盘点</el-button
              >
            </el-form-item> -->
          </el-form>
        </td>
        <td style="text-align:right;vertical-align: top;">
          <el-button @click="exportExcel()" plain>导出</el-button>
        </td>
      </tr>
    </table>

    <table class="table-box">
      <thead>
        <tr>
          <th>盘点单号</th>
          <th>盘点日期</th>
          <th>制单人</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item, index) in tableList" :key="index">
          <td>{{ item.id }}</td>
          <td>{{ item.gmtCreate | changeTime }}</td>
          <td>{{ item.memberName }}</td>
          <td>{{ item.status == 1 ? "正常" : "待审核" }}</td>
          <td v-if="item.status !== 1">
            <el-link
              v-if="qxBtns.update"
              :underline="false"
              @click="addDurg(item, 3)"
              type="primary"
              >修改</el-link
            >&nbsp;
            <el-link
              v-if="qxBtns.audit"
              :underline="false"
              type="primary"
              @click="getDetail(item)"
              >审核</el-link
            >&nbsp;
            <!-- <el-link v-if="qxBtns.delete" :underline="false" @click="onDel(item)" type="danger">删除</el-link> -->
          </td>
          <td v-if="item.status === 1">
            <el-link
              v-if="qxBtns.audit"
              type="primary"
              :underline="false"
              @click="getDetail(item)"
              >查看详情</el-link
            >&nbsp;
          </td>
        </tr>
      </tbody>
    </table>
    <div
      v-if="tableList.length == 0"
      style="color:#999;padding:10px 0;text-align:center;"
    >
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br />
    <pager v-model="pager" @change-pagenum="getData"></pager>
    <!-- <set v-model="dialogEdit" :curItem="curItem" @success="getData"></set> -->
  </section>
</template>
<script>
import Excel from "@/_js/excel.js";
export default {
  name: "storageList",
  data() {
    return {
      dialogJoin: false,
      dialogEdit: false,
      curItem: null,
      pager: { pageSize: 10, pageNum: 1, total: 0 },
      tableList: [],
      form: {
        hpId: "",
        source: 1,
        type: 1,
        name: "", //名称
      },
      typeList: [],
      qxBtns: {},
      dataList: [],
      distype: "2",
      setType: "1",
    };
  },
  created() {
    let th = this;
    th.form.hpId = th.adminUser.hpId;
    th.getQX();
    th.getData();
    th.getBasicData();
    // th.form.putInStorageStartTime=th.getDate(0);
    // th.form.putInStorageEndTime=th.getDate(1);
  },
  methods: {
    onJoin(obj) {
      this.dialogJoin = true;
      this.curItem = obj;
    },
    onDel(obj, index) {
      let th = this;
      th.$confirm(`确定删除吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          let j = { patientId: obj.patientId };
          th.showLoading();
          th.$api.deletePatient(j).then((res) => {
            if (res.executed) {
              th.$message.success("删除成功");
              th.getData();
            } else {
              th.$message.error(res.message);
            }
            th.showLoading(false);
          });
        })
        .catch(() => {});
    },
    getData(type, id) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      if (id != undefined) {
        if (id == -1) {
          th.form.drugTypeId = "";
        } else {
          th.form.drugTypeId = id;
        }
      }
      let j = {};
      Object.assign(j, th.pager);
      Object.assign(j, th.form);
      th.showLoading();
      th.$api.pageQueryMedicalInventory(j).then((res) => {
        if (res.executed) {
          if (res.dataBody != undefined) {
            th.tableList = res.dataBody.list;
            th.pager.total = res.dataBody.total;
          } else {
            th.tableList = [];
            th.pager.total = 0;
          }
        } else {
          th.$message.error(res.message);
        }
        th.showLoading(false);
      });
    },
    addDurg(obj, type) {
      let th = this;
      let j = {};
      if (obj != null) {
        j = {
          id: th.jiaMi(obj.id),
          type: type,
        };
      } else {
        j = {
          id: th.jiaMi(0),
          type: type,
        };
      }
      th.$router.push({
        path: "/page/editInventory",
        query: th.getUrlToken(j),
      });
    },
    getDetail(obj) {
      let th = this;
      let j = {};
      if (obj != null) {
        j = {
          id: th.jiaMi(obj.id),
        };
      } else {
        j = {
          id: th.jiaMi(0),
        };
      }
      th.addNavMenu("盘点详情", "/page/inventoryDetail");
      th.$router.push({
        path: "/page/inventoryDetail",
        query: th.getUrlToken(j),
      });
    },
    getBasicData() {
      let th = this;
      th.getCommonConfigByKey("入库方式").then((res) => {
        th.typeList = res;
      });
    },
    exportExcel() {
      let th = this;
      let j = {};
      th.showLoading(true);
      Object.assign(j, th.pager);
      Object.assign(j, th.form);
      j.pageSize = "1000";
      th.$api.pageQueryMedicalInventory(j).then((res) => {
        if (res.executed) {
          if (res.dataBody != undefined) {
            let data = res.dataBody.list;
            Excel(
              data,
              [
                { key: "id", name: "盘点单号" },
                { key: "gmtCreate", name: "盘点日期" },
                { key: "memberName", name: "制单人" },
                {
                  key: "status",
                  name: "状态",
                  enum: { 1: "正常", 2: "待审核" },
                  type: "enum",
                },
              ],
              "盘点列表"
            );
          } else {
          }
        } else {
          th.$message.error(res.message);
        }
        th.showLoading(false);
      });
    },
  },
  components: {},
};
</script>
